package com.running.base.run.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

/**
 * @program: ShutdownHookImpl
 * @description:
 * @author: baochen.lx
 * @date: 2022-06-13 10:46
 **/
@Component
public class ShutdownHookImpl implements ApplicationListener {

    private Logger logger = LoggerFactory.getLogger(ShutdownHookImpl.class);

    public ShutdownHookImpl() {
        logger.info("初始化ShutdownHook方法.");
    }

    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        if (applicationEvent instanceof ContextClosedEvent) {
            if (((ContextClosedEvent) applicationEvent).getApplicationContext().getParent() == null){
                logger.info("spring context closed event start ...");
            }
        }
    }
}
